﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Centny.PdfReader.util
{
    public class PdfTimer
    {
        public PdfTimer()
        {
            this.TotalTime = 0;
            this.Beg();
        }
        public long TotalTime { get; set; }
        public long LastTime { get; set; }
        public static long Timestamp()
        {
            long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks;
            ticks /= 10000;
            return ticks;
        }
        public void Beg()
        {
            LastTime = Timestamp();
        }
        public long Delay(long limit = 0)
        {
            long now = Timestamp();
            long d = now - LastTime;
            LastTime = now;
            if (d > limit)
            {
                this.TotalTime += d;
            }
            return d;
        }
        public void End(String msg = "time", long limit = 0)
        {
            long delay = this.Delay(limit);
            System.Diagnostics.Debug.WriteLine(msg + ":" + delay);
        }
        public void Total(String msg = "time")
        {
            System.Diagnostics.Debug.WriteLine(msg + ":" + this.TotalTime);
        }
        //
        private static PdfTimer _SharedTimer = new PdfTimer();
        public static PdfTimer SharedTimer
        {
            get
            {
                return _SharedTimer;
            }
        }
    }
}
